//  https://www.luogu.com.cn/problem/P1216

#include<iostream>
using namespace std;

const int N = 1010;
int dp[N], a[N][N];
int n;

int main()
{
    cin >> n;
    for (int i = 1;i <= n;i++)
        for (int j = 1;j <= i;j++)
            cin >> a[i][j];


    for (int i = 1;i <= n;i++)
        for (int j = i;j >= 1;j--)
        {
            dp[j] = max(dp[j - 1] + a[i][j], dp[j] + a[i][j]);
        }

    int ret = 0;
    for (int j = 1;j <= n;j++)
    {
        ret = max(ret, dp[j]);
    }

    cout << ret << endl;

    return 0;
}